package com.example.testservicebind;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;

import java.util.Random;

public class MyService extends Service {
    public MyService() {
    }

    @Override
    public void onCreate() {
        LogUtil.printLog("MyService onCreate");
        super.onCreate();
    }

    // Binder given to clients
    private final IBinder binder = new LocalBinder();
    // Random number generator
    private final Random mGenerator = new Random();
    /**
     * Class used for the client Binder.  Because we know this service always
     * runs in the same process as its clients, we don't need to deal with IPC.
     */
    public class LocalBinder extends Binder {
        MyService getService234() {
            // Return this instance of MyService so clients can call public methods
            return MyService.this;
        }
    }

    @Override
    public IBinder onBind(Intent intent) {
        LogUtil.printLog("MyService.IBinder onBind");
        return binder;
    }

    @Override
    public boolean onUnbind(Intent intent) {
        LogUtil.printLog("MyService.IBinder onUnbind");
        return super.onUnbind(intent);
    }

    /** method for clients */
    public int getRandomNumber() {
        LogUtil.printLog("MyService.getRandomNumber");
        return mGenerator.nextInt(100);
    }

}
